package com.alibaba.aliper.server.model.impl;

import java.util.HashMap;

import com.alibaba.aliper.core.conf.AgentConfig;
import com.alibaba.aliper.server.model.domain.Chart;
import com.alibaba.aliper.server.model.interfaces.AgentControll;
import com.alibaba.aliper.server.model.interfaces.AgentView;
import com.alibaba.aliper.server.model.interfaces.ChartView;

public class Agent implements AgentView , AgentControll{
	public Agent(String agentId){
		this.id = agentId;
	}
	private String id;
	public String getId(){
		return this.id;
	}
	private AgentConfig config = new AgentConfig();
	private HashMap<String,Chart> charts = new HashMap<String, Chart>();
	public synchronized Chart getChartOnCreate(String chartId) {
		Chart chart = null;
		if(!charts.containsKey(chartId)){
			chart = new Chart(chartId);
			charts.put(chartId, chart);
		} else {
			chart = charts.get(chartId);
		}
		return chart;
	}

	public AgentConfig getConfig() {
		return this.config;
	}

	@Override
	public ChartView[] getCharts() {
		return this.charts.values().toArray(new ChartView[this.charts.size()]);
	}

	@Override
	public ChartView getChart(String id) {
		// TODO Auto-generated method stub
		return this.charts.get(id);
	}

	public void restart() {
		for(Chart c : this.charts.values()){
			c.restart();
		}
	}
}
